package eaa.tgi.scrum.services;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import org.springframework.stereotype.Service;

@Service
public class LoadService {

	public static void loadUsers(){

		try {

			Class.forName("org.hsqldb.jdbcDriver");
			Connection c = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/xdb", "sa", "");

			// Table: USERS	
			PreparedStatement pstmt  = c.prepareStatement("INSERT INTO USERS VALUES(1,'Joao','Joao')");
			pstmt.execute();
			pstmt = c.prepareStatement("INSERT INTO USERS VALUES(2,'Roberto','Roberto')");
			pstmt.execute();
			pstmt = c.prepareStatement("INSERT INTO USERS VALUES(3,'Juliana','Juliana')");
			pstmt.execute();
			pstmt = c.prepareStatement("INSERT INTO USERS VALUES(4,'Matheus','Matheus')");
			pstmt.execute();
			pstmt = c.prepareStatement("INSERT INTO USERS VALUES(5,'Clodoaldo','Clodoaldo')");
			pstmt.execute();	

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		loadUsers();
	}

	public static void getUser() {			

		try {
			
			Class.forName("org.hsqldb.jdbcDriver");
			Connection c = DriverManager.getConnection("jdbc:hsqldb:file:testdb", "sa", "");

			// Table: USERS
			PreparedStatement pstmt  = c.prepareStatement("SELECT * FROM USERS");
			pstmt.executeQuery();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
